<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<base href="${BaseContext }">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%--created by yutao on 2017年9月8日 下午3:41:20--%>
<title>展示信息</title>
<link rel="stylesheet" href="http://cdn.amazeui.org/amazeui/2.7.2/css/amazeui.min.css" />
</head>
<body>
    
    <div class="am-container dataDiv">
			<section class="am-panel am-panel-primary">
			  <header class="am-panel-hd">
			    <h3 class="am-panel-title">考试功能演示</h3>
			  </header>
			  <div class="am-panel-bd">
					<table class="am-table am-table-bordered am-text-center">
						<thead>
							<tr>
								<th colspan="3">
									<button title="点击此按钮刷新下方表格数据，ajax处理" class="am-btn am-btn-primary" id="refresh" onclick="refresh()">刷新数据</button>
								</th>
							</tr>
							
						</thead>
						
						<tbody>
						<form id="tijiaoForm">
						<c:forEach items="${list}" var="l">
							<tr>
								<td><input type="checkbox"  onclick="danXuan();" name="danXuan" value="${l.id}"></td>
								<td>${l.userName}</td>
								<td>${l.userAge}岁</td>
							</tr>
						</c:forEach>
						</form>
						<tr>
								
								<td colspan="3">
									<button class="am-btn am-btn-primary" title="点击后将所有数据的checkbox修改为选中状态" onclick="checkAll()">全选</button>
									<button class="am-btn am-btn-primary" title="点击后将所有数据的checkbox修改为未选中状态" onclick="noCheckAll()">全不选</button>
									<button class="am-btn am-btn-primary" title="点击后，已选择的checkbox改为未选择，未选择的checkbox改为已选择" onclick="opposite()">反选</button>
									<button class="am-btn am-btn-warning" title="点击后提交已选择数据的value值" onclick="tijiao()">提交已选择数据</button>
								</td>
							</tr>
						</tbody>
					</table>
					<div>
					
						<p id="warn"></p>
						<p id="lujing"></p>
					</div>
			  </div>
			</section>
		</div>
		

		<script src="static/js/jquery-1.12.4.min.js"></script>
		
		<script type="text/javascript">
		
		function refresh(){
			console.log('刷新页面')
			//alert('刷新页面');
			location.reload();
			
		}

		
			
		function checkAll(){
			var danXuans=document.getElementsByName('danXuan');
			
			for(var i=0;i<danXuans.length;i++){
				var x=danXuans[i];
				x.checked=true;
				
			}
			
		}
		
		function noCheckAll(){
			var danXuans=document.getElementsByName('danXuan');
			for(var i=0;i<danXuans.length;i++){
				var x=danXuans[i];
				x.checked=false;
				
			}
			
		}
		
		function opposite(){
			var danXuans=document.getElementsByName('danXuan');
			for(var i=0;i<danXuans.length;i++){
				var x=danXuans[i];
		  
			if(x.checked==true){
				x.checked=false;
			}else{
				x.checked=true;
			}
			
		 }
		}
		
		
		function tijiao(){
			var danXuans=document.getElementsByName('danXuan');
		    var j=0;	
			for(var i=0;i<danXuans.length;i++){
				var x=danXuans[i];
				
				if(x.checked==true){
				j++;
			   }else{
				   
			   }
		}
			if(j==0){
				//一个都没选
				$('#warn').html('请先选择数据');
				
			}else{
				
				$.post('user/tijiao.do',$('#tijiaoForm').serialize(),function(data){
					
					$('#lujing').html(data.pdir);
					$('#warn').html('');
				});
			}
	}
		
		</script>
    
</body>
</html>